package oop.ex2.expression;

import oop.ex2.exceptions.EmptyExpression;
import oop.ex2.exceptions.ExpectedAtomicExpression;
import oop.ex2.exceptions.ExpectedBinaryOperation;
import oop.ex2.exceptions.TokenNotRecognized;
import oop.ex2.tokenizer.Tokenizer;

/**
 * This Node represents a constant number in the expression.
 * It does not have any children.
 * @author daniel_i_l
 *
 */
public class ConstantNode extends ExpressionNode {
	private final static NodeType NODE_TYPE = NodeType.ATOM;
	private double _value;
	
	/**
	 * Build a constant node using the matched string.
	 * @param matchedString The matched string.
	 */
	public ConstantNode(String matchedString) {
		super(matchedString);
		_nodeType = NODE_TYPE;
		_value = Double.parseDouble(matchedString);
	}

	@Override
	public void generateChildren(Tokenizer tokenizer)
			throws TokenNotRecognized, EmptyExpression,
			ExpectedAtomicExpression, ExpectedBinaryOperation {
		
		//A constant can't have children so just return
		return;

	}

	@Override
	public double calculateNode() {
		return _value;
	}

}
